﻿using System.Web.Routing;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Microsoft.AspNet.SignalR.Infrastructure;
using Ninject;
using Sportsbook.Website.Hubs;
using Sportsbook.Website.Tickers;

namespace Sportsbook.Website.App_Start
{
    public static class SignalRConfig
    {
        public static void RegisterHubs(IKernel kernel)
        {
                var resolver = new NinjectSignalRDependencyResolver(kernel);

                kernel.Bind<LinesTicker>()
                    .To<LinesTicker>()
                    .InSingletonScope();

                kernel.Bind<IHubConnectionContext>().ToMethod(context =>
                        resolver.Resolve<IConnectionManager>().
                            GetHubContext<LinesHub>().Clients
                    ).WhenInjectedInto<LinesTicker>();

                var config = new HubConfiguration()
                {
                    Resolver = resolver
                };

                // Register the default hubs route: ~/signalr/hubs
                RouteTable.Routes.MapHubs(config);
        }
    }
}